#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int tribonacci(int n)
    {
        if (n == 0)
            return 0;
        else if (n == 1 || n == 2)
            return 1;
        int x = 0, y = 0, z = 1, ret = 1;
        for (int i = 3; i <= n; ++i)
        {
            x = y;
            y = z;
            z = ret;
            ret = x + y + z;
        }
        return ret;
    }
};